﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Eis51.CampanyCMS.Model.Bus;
using System.Collections;
using Eis51.CampanyCMS.FrameWork;

namespace Eis51.CampanyCMS.Business.BaseInfoMng
{
    /// <summary>
    /// TypeTree 的摘要说明。
    /// </summary>
    public class TypeTreeDict
    {
        private static volatile TypeTreeDict m_instance = null;

        /// <summary>
        /// 获取多语言化标签
        /// </summary>
        /// <remarks> 
        /// 实现流程： 
        ///		1.使用TagEnumDictView查询  
        ///		2.返回标签   
        ///		3.结束    
        /// </remarks> 
        /// <exception cref="Exception">
        /// 异常描述：出现数据库异常,抛出并回滚事务  
        /// </exception>
        /// <param name="ProductsTypeTreeId">ID</param>
        /// <returns>标签字符串</returns>
        public ProductsType this[int ProductsTypeTreeId]
        {
            get
            {

                foreach (ProductsType o in ProductsTypeTreeData)
                {
                    if (o.Seqno == ProductsTypeTreeId)
                    {
                        return o;
                    }
                }
                return null;
            }
        }



        /// <summary>
        /// 取得 CacheData 对象
        /// </summary>
        /// <remarks>
        /// 实现流程：
        ///     1.锁定类
        ///     2.获取对象实例 
        ///     3.结束
        /// </remarks>
        /// <returns>返回一个已经存在的实体</returns>
        public static TypeTreeDict GetInstance()
        {
            // 通用的必要代码 iBatisNet双校检机制,如果实例不存在
            if (m_instance == null)
            {
                lock (typeof(TypeTreeDict))
                {
                    // 如果实例不存在
                    if (m_instance == null)
                    {

                        // 创建一个的实例
                        m_instance = new TypeTreeDict();

                    }
                }
            }

            // 返回业务逻辑对象
            return m_instance;
        }


        /// <summary>
        /// 类型树数据
        /// </summary>
        public IList ProductsTypeTreeData
        {
            get
            {
                if (Dict.CacheData[CacheName.TypeTree] == null)
                {
                    IList dt = ProductsType.Dt2Objs(BaseDictTagBLL.GetInstance().GetDataTable("select * from Products_Type_Tree"), ProductsType.ColumnNameEnum.DBName);

                    Dict.CacheData[CacheName.TypeTree] = dt;
                }
                return Dict.CacheData[CacheName.TypeTree] as IList;
            }
        }

        public void ClearCache()
        {
            Dict.CacheData.ClearLocalCache(CacheName.TypeTree.ToString());
        }
    }
}
